﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using G.Controls;
using G.WeiBo.WebAPI.Domain;
using G.WeiBo.WebAPI.Response;
using G.WeiBo.WebAPI.Request;
using G.WeiBo.WebAPI;
using G.Navigate;

namespace G.WeiBo.View.ChildWindows
{
    public partial class ForwardMessage : ChildWindow
    {
        DefaultClient client = GlobalStaticData.Client;
        private Message message;
        public ForwardMessage(Message msg)
        {
            InitializeComponent();
            this.message = msg;
            this.txtMessage.Text = this.message.Text;
            //if (message.Retweeted != null)
            //{

            //}
            //else
            //{
            //    this.checkBoxIsAddOri.Visibility = System.Windows.Visibility.Collapsed;
            //}
        }
        private void btnSms_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Phone.Tasks.PhoneNumberChooserTask pTask = new Microsoft.Phone.Tasks.PhoneNumberChooserTask();
            pTask.Completed += new EventHandler<Microsoft.Phone.Tasks.PhoneNumberResult>(pTask_Completed);
            pTask.Show();
        }

        void pTask_Completed(object sender, Microsoft.Phone.Tasks.PhoneNumberResult e)
        {
            if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
            {
                Microsoft.Phone.Tasks.SmsComposeTask task = new Microsoft.Phone.Tasks.SmsComposeTask();
                task.Body = this.message.Text;
                task.To = e.PhoneNumber;
                task.Show();
            }
        }

        private void btnEamil_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Phone.Tasks.EmailAddressChooserTask eTask = new Microsoft.Phone.Tasks.EmailAddressChooserTask();
            eTask.Completed += new EventHandler<Microsoft.Phone.Tasks.EmailResult>(eTask_Completed);
            eTask.Show();
        }

        void eTask_Completed(object sender, Microsoft.Phone.Tasks.EmailResult e)
        {
            if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
            {
                Microsoft.Phone.Tasks.EmailComposeTask task = new Microsoft.Phone.Tasks.EmailComposeTask();
                task.Body = this.message.Text + "</br>" + this.message.Original_pic;
                task.Subject = "来自WP7微博客户端微博转发";
                task.To = e.Email;
                task.Show();
            }
        }

        private void btnRe_Click(object sender, RoutedEventArgs e)
        {
            client.Execute(new RepostRequest { ID = message.Id, Content = this.txtContent.Text }, (c) =>
            {
                if (!c.IsError)
                {
                    PhoneApplicationPageHelp.ShowState("转发成功!");
                    this.IsOpen = false;
                }
            });
        }

        private void checkBoxIsAddOri_Checked(object sender, RoutedEventArgs e)
        {
            this.txtContent.Text += string.Format("//@{0}:{1} ", this.message.User.NickName, this.message.Text);
        }
    }
}
